﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ZK.YHP_TransManage.Test
{
    public partial class 筒仓测试 : Form
    {
        public 筒仓测试()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            BB bB = new BB();
        }
    }
    public class BB
    {
        public SerialPort serialPort;
        public BB()
        {
            serialPort = new SerialPort("COM2", 1200, Parity.Even, 7, StopBits.Two);
            serialPort.Open();
            serialPort.DataReceived += SerialPort_DataReceived;
            Common.Log4.LogManage.WriteInfo("is ok");
        }

        private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            System.Threading.Thread.Sleep(500);
            // byte[] ReDatas1 = new byte[serialPort.BytesToRead];
            byte[] ReDatas = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D };
            serialPort.Read(ReDatas, 0, ReDatas.Length);//读数据
            //var aaa = serialPort.ReadExisting();



            Common.Log4.LogManage.WriteInfo(string.Join("-", ReDatas));
            //Common.Log4.LogManage.WriteInfo(aaa);
        }
    }
}
